package com.example.controller.statistics;


import com.alibaba.fastjson.JSON;
import com.example.pojo.StatisticalAnalysisCP;
import com.example.service.statistics.StatisticalAnalysisCPService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


//统计图汇总--课程和商品的折线统计图
@RestController
//@RequestMapping("/StatisticalAnalysisCP")
public class StatisticalAnalysisCPController {

    @Autowired
    private StatisticalAnalysisCPService sacpService;

    @RequestMapping("/echarts")
    public String getEcharts(){
        List<StatisticalAnalysisCP> sacp = sacpService.getAllEcharts();

        Map<String, Object> map = new HashMap<>();
        List<String> xingQi = new ArrayList<>();
        List<Integer> sac = new ArrayList<>();
        List<Integer> sap = new ArrayList<>();

        for (int i = 0; i < sacp.size(); i++) {
            xingQi.add(sacp.get(i).getXingQi());
            sac.add(sacp.get(i).getSac());
            sap.add(sacp.get(i).getSap());
        }
        map.put("xingQi",xingQi);
        map.put("sac",sac);
        map.put("sap",sap);
        
        String map_string = JSON.toJSONString(map);
        return map_string;
    }
}
